From: Florian Müllner Date: Sun, 21 Jan 2024 17:50:54 +0000 (+0100) Subject: tests: Fix check for global scope pollution X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~2^2~112 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=b02460fa633390e8224aa16c8bb52f582df90b6e;p=gnome-shell.git tests: Fix check for global scope pollution Since commit c570011 dropped the `with` statement, this bit of the test has only checked for writes to a specific variable in the file. There is no direct replacement for `with` here, the best we can do (I think) is comparing property names on the global objects before and after the `eval()` call. Part-of: --- diff --git a/tests/unit/jsParse.js b/tests/unit/jsParse.js index 9dac85c19..37e2e0cb9 100644 --- a/tests/unit/jsParse.js +++ b/tests/unit/jsParse.js @@ -210,8 +210,8 @@ for (let i = 0; i < testsIsUnsafeExpression.length; i++) { for (let i = 0; i < testsModifyScope.length; i++) { let text = testsModifyScope[i]; - // We need to use var here for the with statement - var obj = {}; + + const globalPropsPre = Object.getOwnPropertyNames(globalThis).sort(); // Just as in JsParse.getCompletions, we will find the offset // of the expression, test whether it is unsafe, and then eval it. @@ -232,6 +232,8 @@ for (let i = 0; i < testsModifyScope.length; i++) { } } } - let propertyNames = Object.getOwnPropertyNames(obj); - JsUnit.assertEquals(`The context '${JSON.stringify(obj)}' was not modified`, propertyNames.length, 0); + + const globalPropsPost = Object.getOwnPropertyNames(globalThis).sort(); + Assertions.assertArrayEquals('The global object was not modified', + globalPropsPre, globalPropsPost); }